package com.smec.remes.util;

import android.app.Dialog;
import android.content.Context;
import android.os.Bundle;
import android.support.v7.app.AlertDialog;
import android.view.Gravity;
import android.view.LayoutInflater;
import android.view.View;
import android.view.Window;
import android.view.WindowManager;
import android.widget.Button;

import com.smec.moblie.R;
import com.weigan.loopview.LoopView;
import com.weigan.loopview.OnItemSelectedListener;

import java.util.ArrayList;

/**
 * Created by Administrator on 2017/12/9.
 */

public class RollerDialog extends Dialog {
    private Context context;
    private View customView;
    private String num="0";
    private String num2="0";
    private String num3="1";

    public RollerDialog(Context context, int themeResId) {
        super(context, themeResId);
        this.context = context;
        this.setCanceledOnTouchOutside(true);
        //获取当前Activity所在的窗体
        Window dialogWindow = this.getWindow();
        //设置Dialog从窗体底部弹出
        dialogWindow.setGravity( Gravity.BOTTOM);
        //获得窗体的属性
        WindowManager.LayoutParams lp = dialogWindow.getAttributes();
        lp.y = 20;//设置Dialog距离底部的距离
//       将属性设置给窗体
        dialogWindow.setAttributes(lp);
        LayoutInflater inflater = LayoutInflater.from(context);
        customView = inflater.inflate(R.layout.dialog_view, null);
        getNum(customView);
    }

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        this.setContentView(customView);
    }

    public View findViewById(int id) {
        return super.findViewById(id);
    }

    public View getCustomView() {
        return customView;
    }

    public void getNum(View view){
        LoopView loopView = (LoopView) view.findViewById(R.id.loopView);
        LoopView loopView2= (LoopView) view.findViewById(R.id.loopView2);
        LoopView loopView3 = (LoopView) view.findViewById(R.id.loopView3);
        ArrayList<String> list = new ArrayList<>();
        for (int i = 0; i <10; i++) {
            list.add(String.valueOf(i));
        }
        // 滚动监听
        loopView.setListener(new OnItemSelectedListener() {
            @Override
            public void onItemSelected(int index) {
                num= String.valueOf(index);
            }
        });
        // 设置原始数据
        loopView.setItems(list);
        loopView.setInitPosition(0);

        loopView2.setListener(new OnItemSelectedListener() {
            @Override
            public void onItemSelected(int index) {
                num2= String.valueOf(index);
            }
        });
        // 设置原始数据
        loopView2.setItems(list);
        loopView2.setInitPosition(0);

        loopView3.setListener(new OnItemSelectedListener() {
            @Override
            public void onItemSelected(int index) {
                num3= String.valueOf(index);
            }
        });
        // 设置原始数据
        loopView3.setItems(list);
        loopView3.setInitPosition(1);
    }

    public void reduction(){
        num="0";
        num2="0";
        num3="1";
    }

    public String Num(){
        if(num.equals("0")&&num2.equals("0")){
            return num3;
        }else if(num.equals("0")){
            return  num2+num3;
        }else {
            return  num+num2+num3;
        }

    }
}
